{extend name="base" /}
{block name="resourse"}
<link rel="stylesheet" href="__STATIC__/plugins/spectrum/spectrum.css">
<style>
    .edui-editor{z-index: 1!important;}
</style>
{/block}
{block name="main"}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>添加文章</legend>
    </fieldset>
    <form class="layui-form" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">栏目</label>
            <div class="layui-input-4" id="box_catid">
                <select id="catid" lay-verify="required" name="catid" validate=" minlength:1, maxlength:6, required:true" title="必须选择一个栏目"><option value="">请选择栏目</option><option value="1" disabled=""> 最新动态</option><option value="5" selected="">&nbsp;├ CLTPHP动态</option><option value="6">&nbsp;└ 相关知识 </option><option value="3"> CLTPHP服务</option></select><div class="layui-unselect layui-form-select"><div class="layui-select-title"><input type="text" placeholder="请选择栏目" value="&nbsp;├ CLTPHP动态" readonly="" class="layui-input layui-unselect"><i class="layui-edge"></i></div><dl class="layui-anim layui-anim-upbit"><dd lay-value="" class="layui-select-tips">请选择栏目</dd><dd lay-value="1" class=" layui-disabled"> 最新动态</dd><dd lay-value="5" class="layui-this">&nbsp;├ CLTPHP动态</dd><dd lay-value="6" class="">&nbsp;└ 相关知识 </dd><dd lay-value="3" class=""> CLTPHP服务</dd></dl></div>                    </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-4" id="box_title">
                <input type="text" name="title" data-required="1" value="" data-min="1" data-max="80" data-errormsg="标题必须为1-80个字符" title="标题" placeholder="请输入标题" lay-verify="defaul" class="title layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux red">*必填</div>
        </div>
        <div class="layui-form-item"><label class="layui-form-label">标题颜色</label><div class="layui-input-4"><input type="text" name="style_color" id="style_color" value="" style="display: none;">
            <div class="sp-replacer sp-light"><div class="sp-preview"><div class="sp-preview-inner" style="background-color: rgb(0, 0, 0);"></div>
            </div><div class="sp-dd">▼</div>
            </div></div>
        </div>
        <div class="layui-form-item"><label class="layui-form-label">加粗</label>
            <div class="layui-input-4"><input type="checkbox" name="style_bold" value="bold" title="加粗">
                <div class="layui-unselect layui-form-checkbox" lay-skin=""><span>加粗</span><i class="layui-icon"></i></div>
            </div>
        </div>
        <div class="layui-form-item"><label class="layui-form-label">缩略图</label>
            <div class="layui-input-4"><input type="hidden" name="thumb" id="thumb" value="">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-primary" id="thumbBtn"><i class="icon icon-upload3"></i>点击上传</button>
                    <input class="layui-upload-file" type="file" name="file">
                    <div class="layui-upload-list">
                        <img class="layui-upload-img" id="cateImage">
                        <p id="thumbText"></p>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">关键词</label>
            <div class="layui-input-4" id="box_keywords">
                <input type="text" data-required="0" min="0" max="80" errormsg="" title="关键词" placeholder="请输入关键词" lay-verify="defaul|" class=" layui-input" name="keywords" value="">                     </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">内容</label>
            <div class="layui-input-4" id="box_content">
                <input type="hidden" id="editType" value="1">
                <div class="content edui-default" id="content" style="">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">发布时间</label>
            <div class="layui-input-4" id="box_createtime">
                <input type="datetime" title="发布时间" name="createtime" data-required="1" placeholder="请输入发布时间" value="2018-07-29 21:47:02" class=" layui-input" id="addtime" lay-key="1"></div><div class="layui-form-mid layui-word-aux red">*必填                    </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-4" id="box_status">
                <input name="status" id="status_1" checked="" value="1" type="radio" class="ace" title="发布"><div class="layui-unselect layui-form-radio layui-form-radioed"><i class="layui-anim layui-icon"></i><span>发布</span></div><input name="status" id="status_2" value="2" type="radio" class="ace" title="定时发布"><div class="layui-unselect layui-form-radio"><i class="layui-anim layui-icon"></i><span>定时发布</span></div>                    </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">来源</label>
            <div class="layui-input-4" id="box_copyfrom">
                <input type="text" data-required="0" min="0" max="0" errormsg="" title="来源" placeholder="请输入来源" lay-verify="defaul" class="copyfrom layui-input" name="copyfrom" value="CLTPHP">                     </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">来源网址</label>
            <div class="layui-input-4" id="box_fromlink">
                <input type="text" data-required="0" min="0" max="0" errormsg="" title="来源网址" placeholder="请输入来源网址" lay-verify="defaul" class="fromlink layui-input" name="fromlink" value="http://www.cltphp.com/">                     </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">点击次数</label>
            <div class="layui-input-4" id="box_hits">
                <input type="text" class="input-text  layui-input" name="hits" id="hits" value="0" size="10" validate=" maxlength:8">                     </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">提交</button>
                <a href="/admin/article/index/catid/5.html" class="layui-btn layui-btn-primary">返回</a>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="javascript"}
<script>
    var ADMIN = '/static/admin';
    var PUBLIC = "__PUBLIC__";
    var imgClassName,fileClassName;
</script>
<script>
    var edittext=new Array();
</script>
<script src="__STATIC__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__STATIC__/ueditor/ueditor.all.min.js" type="text/javascript"></script>
<script src='__COMMON__/js/layui-mz-min.js'></script>
<script>
    var ue = UE.getEditor('content');
    var thumb,pic,file;
    var url= "<?php echo url('insert'); ?>";

    layui.use(['form','upload','layedit','laydate','jquery'], function () {

        var form = layui.form,upload = layui.upload,layedit = layui.layedit,laydate = layui.laydate,$ = layui.jquery;

        form.on('select(province)', function(data) {
            var pid = data.value;
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.get("<?php echo url('getRegion'); ?>?pid=" + pid, function (data) {
                layer.close(loading);
                var html='<option value="">请选择市</option>';
                $.each(data, function (i, value) {
                    html += '<option value="'+value.id+'">'+value.name+'</option>';
                });
                $('#city').html(html);
                $('#district').html('<option value="">请选择县/区</option>');
                form.render()
            });
        });
        form.on('select(city)', function(data) {
            var pid = data.value;
            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.get("<?php echo url('getRegion'); ?>?pid=" + pid, function (data) {
                layer.close(loading);
                var html='<option value="">请选择县/区</option>';
                $.each(data, function (i, value) {
                    html += '<option value="'+value.id+'">'+value.name+'</option>';
                });
                $('#district').html(html);

                form.render()
            });
        });
        layui.selMeltiple($);
        //缩略图上传
        upload.render({
            elem: '#thumbBtn'
            ,url: '<?php echo url("UpFiles/upload"); ?>'
            ,accept: 'images' //普通文件
            ,exts: 'jpg|png|gif' //只允许上传压缩文件
            ,done: function(res){
                console.log(res);
                $('#cltThumb').attr('src',res.url);
                $('#thumb').val(res.url);
            }
        });
        //日期
        laydate.render({
            elem: '#addtime', //指定元素
            type:'datetime',
            format:'yyyy-MM-dd HH:mm:ss'
        });
        form.on('submit(submit)', function (data) {
            if(edittext){
                for (key in edittext){
                    data.field[key] = $(window.frames["LAY_layedit_"+edittext[key]].document).find('body').html();
                }
            }
            $.post(url, data.field, function (res) {
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
        });
        $('.layui-row').on('click','.delimg',function(){
            var thisimg = $(this);

            layer.confirm('你确定要删除该图片吗？', function(index){
                thisimg.parents('.layui-col-md3').remove();
                layer.close(index);
            })
        })
    });

</script>
{/block}